package com.kaka.bus.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.kaka.bus.R;

/**
 * Created by OnionMac on 2018/4/3.
 */

public class BannerIndicator extends LinearLayout {
    private String TAG = "zhangqi";
    private int selectDrawable = R.drawable.select_drawable;
    private int unSelectDrawable = R.drawable.un_select_drawable;
    private int size;
    public BannerIndicator(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        setOrientation(LinearLayout.HORIZONTAL);
    }

    public void setSize(int size){
        this.size = size;
        removeAllViews();
        if(size <= 1){
            return;
        }
        for (int i = 0; i < size; i++) {
            ImageView iv = new ImageView(getContext());
            if(i == 0){
                iv.setImageResource(selectDrawable);
            }else{
                iv.setImageResource(unSelectDrawable);
            }
            this.addView(iv);
            LayoutParams lp = (LayoutParams) iv.getLayoutParams();

            lp.rightMargin = DensityUtil.dp2px(10);
            iv.setLayoutParams(lp);
        }
    }

    public void refresh(int position){
        for (int i = 0; i < getChildCount(); i++) {
            ImageView iv = (ImageView) getChildAt(i);
            if(i == position){
                iv.setImageResource(selectDrawable);
            }else{
                iv.setImageResource(unSelectDrawable);
            }
        }
    }

    private void initView() {

    }
}
